﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLKHO.Class;

namespace QLKHO.Forms
{
    public partial class frmPhieuXuatKho : Form
    {
        public frmPhieuXuatKho()
        {
            InitializeComponent();
            this.pHIEUXUATKHOTableAdapter.Fill(this.qLKHODataSet.PHIEUXUATKHO);
            clsMain.flexConn.InitForms(this.Tag.ToString(), this, qLKHODataSet.PHIEUXUATKHO);
            clsMain.flexConn.InitForms(this.Tag.ToString(), ref fcButton1);
            clsMain.flexConn.InitForms(this.Tag.ToString(), ref dataGridView1);
            clsMain.flexConn.KhoiTaoXMLTable(this.Tag.ToString(), qLKHODataSet.PHIEUXUATKHO);
                
        }

        private void frmPhieuXuatKho_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'qLKHODataSet.NHANVIEN' table. You can move, or remove it, as needed.
            this.nHANVIENTableAdapter.Fill(this.qLKHODataSet.NHANVIEN);
            // TODO: This line of code loads data into the 'qLKHODataSet.KHO' table. You can move, or remove it, as needed.
            this.kHOTableAdapter.Fill(this.qLKHODataSet.KHO);
            // TODO: This line of code loads data into the 'qLKHODataSet.PHIEUXUATKHO' table. You can move, or remove it, as needed.
            this.pHIEUXUATKHOTableAdapter.Fill(this.qLKHODataSet.PHIEUXUATKHO);
            txtThanhTien.fcText = "0";
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
            clsMain.flexConn.AddDataToControls(this.Tag.ToString(), e.RowIndex, qLKHODataSet.PHIEUXUATKHO);
            
                clsMain.strMSPhieuXuatKho = qLKHODataSet.PHIEUXUATKHO.Rows[e.RowIndex][0].ToString();
                clsMain.strMSKho = qLKHODataSet.PHIEUXUATKHO.Rows[e.RowIndex][1].ToString();
                butChiTietPhieuXuat.Enabled = true;
                butInBaoCao.Enabled = true;
            }
        }

        private void fcButton1_Click(object sender, EventArgs e)
        {
            clsMain.flexConn.ButtonsClick(this.Tag.ToString(), fcButton1.intState);
            pHIEUXUATKHOTableAdapter.Update(qLKHODataSet.PHIEUXUATKHO);
            if (txtThanhTien.fcText == "")
                txtThanhTien.fcText = "0";
            butChiTietPhieuXuat.Enabled = false;
            butInBaoCao.Enabled = false;
        }

        private void butChiTietPhieuXuat_Click(object sender, EventArgs e)
        {
            frmChiTietPhieuXuat frm = new frmChiTietPhieuXuat();
            frm.ShowDialog();
            foreach (DataRow row in qLKHODataSet.PHIEUXUATKHO)
            {
                if (row["MASO"].ToString() == clsMain.strMSPhieuXuatKho)
                {
                    row["THANHTIEN"] = clsMain.intThanhTien;
                    pHIEUXUATKHOTableAdapter.Update(row);
                }
            }
        }

        private void butInBaoCao_Click(object sender, EventArgs e)
        {
            frmReportPhieuXuatKho frm = new frmReportPhieuXuatKho();
            frm.Show();
        }
    }
}
